<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="header.jsp"%>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form id="formId" class="layui-form layui-form-pane" action="">
	  <input type="hidden" name="id" value="${user.id}"/>
	  <div class="layui-form-item">
	    <label class="layui-form-label">用户名</label>
	    <div class="layui-input-block">
	      <input type="text" name="name" value="${user.name}" autocomplete="off" placeholder="请输入用户名" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">年龄</label>
	    <div class="layui-input-block">
	      <input type="text" name="age" value="${user.age}" autocomplete="off" placeholder="请输入年龄" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">邮箱</label>
	    <div class="layui-input-block">
	      <input type="text" name="email" value="${user.email}" autocomplete="off" placeholder="请输入邮箱" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">密码</label>
	    <div class="layui-input-block">
	      <input type="text" name="password" value="${user.password}" autocomplete="off" placeholder="请输入密码" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">请选择部门</label>
	    <div class="layui-input-inline">
	      <select name="departmentId">
	        <option value="">请选择省</option>
	        <c:forEach items="${departmentList}" var="department">
	        	<c:if test="${user.departmentId==department.id}">
	        		<option selected="" value="${department.id}">${department.name}</option>
	        	</c:if>
	        	<c:if test="${user.departmentId!=department.id}">
	        		<option value="${department.id}">${department.name}</option>
	        	</c:if>
	        </c:forEach>
	      </select>
	    </div>
	   </div>
  	   <div class="layui-form-item">
		    <label class="layui-form-label">选择角色</label>
		    <div class="layui-input-block">
		       <c:forEach items="${roleList}" var="role">
		       		<c:if test="${role.checked}">
			            <input checked type="checkbox" name="roleIds" value="${role.id}"  title="${role.name}">
		       		</c:if>
		       		<c:if test="${!role.checked}">
			            <input type="checkbox" name="roleIds" value="${role.id}"  title="${role.name}">
		       		</c:if>
	           </c:forEach>
		    </div>
	   </div>
	    <input  type="button" class="layui-btn" value="修改" onclick="submitForm()">
	   
   </form>
   
   <script type="text/javascript">
   		layui.use(['form', 'laydate'], function() {
   			var form = layui.form;
   		});
   		
   		function submitForm(){
			$.post(
				'${path}/user?method=update',
				$('#formId').serialize(),
				function(jsonResult) {
					console.log(jsonResult);
					if (jsonResult.code == 0) {
						console.log(jsonResult);
						mylayer.okMsg(jsonResult.msg);
						
						//当你在iframe页面关闭自身时获得当前弹出框的index索引
		                var index = parent.layer.getFrameIndex(window.name);
	                     
	                     // js一个方法，定时器，1000毫秒之后自动执行function里面的代码
	                     setTimeout(function() {
	                         // 关闭弹出层
	                         parent.layer.close(index);
	                         // 刷新父页面
	                         window.parent.location.reload();
	                     }, 1000);
					} else {
						mylayer.errorMsg(jsonResult.msg);
					}
				},
				'json'
			);
		}
   </script>
</body>
</html>